POV-Ray : Newsgroups : povray.general : Problem with Parse_String and #ifndef : Problem with Parse_String and #ifndef Server Time
4 Nov 2024 21:23:05 EST (-0500)
  Problem with Parse_String and #ifndef  
From: Florian Brucker
Date: 10 Sep 2003 12:21:10
Message: <3f5f4f76$1@news.povray.org>
Hey Guys!

I want to check if a certain pigment is already defined and otherwise 
define it. Normally that would be no problem, #ifndef does the job.

Unfortunately, I create my pigments dynamically within the SDL code. 
Every pigment gets a number. The pigment's name would be

	Parse_String(concat("Pigment",str(Number,0,0)))

but this does not work with #indef. The following code reports: "Parse 
Error: Expexted ')', '(' found instead". The error occurs right after 
"Parse_String" in the code:

<code>
#include "strings.inc"

#local Number = 34;
#local PigmentName = concat("Pigment",str(Number,0,0));

#ifndef(Parse_String(PigmentName))
	#debug "no pigment defined, yet\n"
#end
</code>

I understand this from the parser's point of view - normaly, opening 
brackets inside #ifndef() do not make sense, as identifiers aren't 
allowed to contain brackets. In the case of Parse_String(), however, 
it makes sense.

I see no reason to rewrite the parser because of this, but I'd like to 
know if there is another possibility to check if an identifier from 
which I got only the name as a string is already declared.

BTW, declaring such an identifier is possible: while

<code>
#declare Parse_String(PigmentName) = pigment { rgb<1,0,0> }
</code>

gives an error,

<code>
Parse_String(concat("#declare ",PigmentName)) = pigment { rgb<1,0,0> }
</code>

works perfectly.

Thanks in advance,
Florian
-- 
//=================[web: http://www.torfbold.com]==================\\
#local a=-5;#while(a<5)sphere{<sin(a*pi)*5a*10pow(a,5)*.01>sin(a*a*a*
.1)+1pigment{rgb 9*z}}#local a=a+.01;#end camera{look_at-y*10location
<8,-3,-8>*10}// [www.povray.org]     [www.imp.org]     [www.irtc.org]


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.